<template>
    <div>
        <el-tabs>
            <el-tab-pane  label="入库单 ">
                <el-form :model="inWare" label-width="110px" style="overflow:hidden">
                    <el-form-item prop="inDan" label="入库单号" class="inline__">
                        <el-input v-model="inWare.inDan" :readonly="true"></el-input>
                    </el-form-item>
                    <el-form-item prop="emp" label="入库员" class="inline__">
                        <el-select v-model="inWare.emp" placeholder="请选择入库员" value-key="empId">
                            <el-option v-for="i in empList" :key="i.empId" :label="i.empName" :value="i"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="inDate" label="入库日期" class="inline__">
                        <el-input :readonly="true">
                            <span style="color:rgb(110,110,110);margin-left: 10px;font-size: 13px" slot="prefix">{{inWare.inDate | format_date}}</span>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="remark" label="备注" class="inline__">
                        <el-input v-model="inWare.remark"></el-input>
                    </el-form-item>
                    <el-form-item style="margin-left:130px;">
                        <el-button type="primary" @click="addIn">保存</el-button>
                        <el-button @click="cancel">取消</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<script>
    export default {
        name: "add_in",
        data:function () {
            return{
                //入库员数据
                empList:[],
                //新增入库单数据
                inWare:{
                    inId:0,
                    inDan:this.$store.state.vueAppCai.inDan,
                    inDate:new Date,
                    state:0,
                    remark:'',
                    emp:this.$store.state.user,
                    caigou:{}
                }
            }
        },
        methods:{
            //初始化入库员数据
            init(){
                this.axios.get("api/ware-emp").then(v=>{
                    this.empList=v.data;
                }).catch()
            },
            //新增入库单
            addIn(){
                this.inWare.caigou=this.$store.state.vueAppCai.detailData;
                this.$axios.post("api/ware/add_in",this.inWare).then(() => {
                        this.clear();
                        this.$store.state.vueAppCai.inVisible = false;
                        if(this.$store.state.vueAppCai.get_in){
                            this.$store.state.vueAppCai.currPage=1;
                            this.$store.state.vueAppCai.get_in(1);
                        }else{
                            this.$router.push({
                                path:"/in_index"
                            })
                        }
                        this.global.mes_success("生成入库单成功");
                    }).catch()
            },
            //取消新增
            cancel(){
                this.$store.state.vueAppCai.inVisible = false;
                this.clear();
            },
            //清空新增采购表数据
            clear(){
                this.inWare={
                    inId:0,
                    inDan:this.$store.state.vueAppCai.inDan,
                    inDate:new Date,
                    state:0,
                    remark:'',
                    emp:this.$store.state.user,
                    caigou:{}
                }
            }
        },
        created() {
            this.init()
        }
    }
</script>
<style scoped>
    .inline__{width:90%!important;display:inline-block}
    .el-select{width:100%!important;}
</style>